package com.meiyou.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.meiyou.pojo.DongtaiDianzan;
import com.meiyou.pojo.NewPinglun;
import com.meiyou.pojo.PinglunDianzan;
import com.meiyou.service.NewPinglunService;
import com.meiyou.utils.Msg;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Controller
@Api(value = "评论点赞接口", tags = { "评论点赞接口" })
@RequestMapping("/newPinglun")
public class NewDianzanController {

	
	@Autowired
	NewPinglunService pinglinService;
	
	//添加评论
	@RequestMapping(value="/addpinglun",method=RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value="添加评论",notes="添加评论",httpMethod="POST")
	public Msg register(NewPinglun pinglun) {
		
		pinglinService.addPinglun(pinglun);
		return Msg.success();  
	}
	
	//根据动态Id查询评论条数
	@RequestMapping(value="/selectshuliang",method=RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value="根据动态Id查询评论条数",notes="根据动态Id查询评论条数",httpMethod="POST")
	public Msg selectshuliang(String dongtaiId) {

		List<NewPinglun> list = pinglinService.selectAllPinglunById(dongtaiId);
		return Msg.success().add("list", list);  
	}
	
	
	 //<!-- 添加动态点赞 -->
	@RequestMapping(value="/addDongtaiDianzan",method=RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value="添加动态点赞 ",notes="添加动态点赞 ",httpMethod="POST")
	public Msg addDongtaiDianzan(DongtaiDianzan dongtaiDianzan) {
		pinglinService.addDongtaiDianzan(dongtaiDianzan);
		return Msg.success();
	}
	
	//<!-- 取消动态点赞 -->
	@RequestMapping(value="/quxiaoDongtaiDianzan",method=RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value="取消动态点赞",notes="取消动态点赞",httpMethod="POST")
	public Msg quxiaoDongtaiDianzan(String dongtaiId,int dianzanUserId) {
		
		DongtaiDianzan dongtaiDianzan = new DongtaiDianzan();
		dongtaiDianzan.setDongtaiId(dongtaiId);
		dongtaiDianzan.setDianzanUserId(dianzanUserId);
		pinglinService.quxiaoDongtaiDianzan(dongtaiDianzan);
		return Msg.success();
	}
	
	// <!-- 添加评论点赞 -->
	@RequestMapping(value="/addPinglunDianzan",method=RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value="添加评论点赞 ",notes="添加评论点赞 ",httpMethod="POST")
	public Msg addPinglunDianzan(PinglunDianzan pinglunDianzan) {
		
		pinglinService.addPinglunDianzan(pinglunDianzan);
		return Msg.success();
	}
	
	// <!-- 取消评论点赞 -->
    @RequestMapping(value="/quxiaoPinglunDianzan",method=RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value="取消评论点赞 ",notes="取消评论点赞",httpMethod="POST")
	public Msg quxiaoPinglunDianzan(int pinglunId,int dianzanUserId) {
		
		PinglunDianzan pinglunDianzan = new PinglunDianzan();
		pinglunDianzan.setDianzanUserId(dianzanUserId);
		pinglunDianzan.setPinglunId(pinglunId);
		pinglinService.quxiaoPinglunDianzan(pinglunDianzan);
		return Msg.success();
	}
	
	 //<!-- 查询动态点赞数 -->
    @RequestMapping(value="/selectDongtaidianzanById",method=RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value="查询动态点赞数 ",notes="查询动态点赞数",httpMethod="POST")
	public Msg selectDongtaidianzanById(String dongtaiId) {
		
    	int shuliang;
		List<DongtaiDianzan> list = pinglinService.selectDongtaidianzanById(dongtaiId);
		if(list!=null || list.size()!=0) {
			shuliang = list.size();
		}else {
			shuliang = 0;
		}
		return Msg.success().add("shuliang", shuliang);
	}
	
	//<!-- 查询动态评论数 -->
    @RequestMapping(value="/selectDongtaiPinglunById",method=RequestMethod.POST)
 	@ResponseBody
 	@ApiOperation(value="查询动态评论数 ",notes="查询动态评论数",httpMethod="POST")
	public Msg selectDongtaiPinglunById(String dongtaiId) {
		
		List<NewPinglun> list = pinglinService.selectDongtaiPinglunById(dongtaiId);
		
		return Msg.success().add("list", list);
	}
	
	/*
	 * //<!-- 根据用户Id查询未通知评论 1 表示未读 2 表示已读 -->
	 * 
	 * @RequestMapping(value="/selectIsNotReadPinglun",method=RequestMethod.POST)
	 * 
	 * @ResponseBody
	 * 
	 * @ApiOperation(value="根据用户Id查询未通知评论 ",notes="根据用户Id查询未通知评论",httpMethod="POST")
	 * public Msg selectIsNotReadPinglun(String userId){
	 * 
	 * List<NewPinglun> list = pinglinService.selectIsNotReadPinglun(userId);
	 * 
	 * //修改为已读 pinglinService.updateNotReadToReadForPinglun(); return
	 * Msg.success().add("list", list); }
	 * 
	 * //<!-- 根据用户Id查询未通知动态点赞 1 表示未读 2 表示已读 -->
	 * 
	 * @RequestMapping(value="/selectIsNotReadDontaiDianzan",method=RequestMethod.
	 * POST)
	 * 
	 * @ResponseBody
	 * 
	 * @ApiOperation(value="根据用户Id查询未通知动态点赞 ",notes="根据用户Id查询未通知动态点赞",httpMethod=
	 * "POST") public Msg selectIsNotReadDontaiDianzan(String userId){
	 * 
	 * List<DongtaiDianzan> list =
	 * pinglinService.selectIsNotReadDontaiDianzan(userId); //修改为已读
	 * pinglinService.updateNotReadToReadForDongtaiDianzan(); return
	 * Msg.success().add("list", list); }
	 * 
	 * //<!-- 根据用户Id查询未通知评论点赞 1 表示未读 2 表示已读 -->
	 * 
	 * @RequestMapping(value="/selectIsNotReadPinglunById",method=RequestMethod.
	 * POST)
	 * 
	 * @ResponseBody
	 * 
	 * @ApiOperation(value="根据用户Id查询未通知评论点赞  ",notes="根据用户Id查询未通知评论点赞 ",httpMethod=
	 * "POST") public Msg selectIsNotReadPinglunById(String userId){
	 * 
	 * List<PinglunDianzan> list =
	 * pinglinService.selectIsNotReadPinglunById(userId); //修改为已读
	 * pinglinService.updateNotReadToReadForPinglunDianzan(); return
	 * Msg.success().add("list",list); }
	 */
	
}
